-
Notifications
You must be signed in to change notification settings - Fork 211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CLI
: add option --clean-workdir
to verdi node delete
#6756
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #6756 +/- ##
==========================================
+ Coverage 78.15% 78.19% +0.05%
==========================================
Files 564 564
Lines 42643 42677 +34
==========================================
+ Hits 33322 33367 +45
+ Misses 9321 9310 -11 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @khsrali , thanks for addressing the issues. I added a few comments on the code. I am not familiar with tests in aiida-core, so no comments on that part.
@click.option( | ||
'--clean-workdir', | ||
is_flag=True, | ||
help='Also clean the remote work directory. (only applies to workflows and CalcJobNodes)', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
only applies to workflows and CalcJobNodes
It is better to revise this message because this applies to any node, as a node can be an input of the workchain or calcjob.
e.g., but could be improved.
help='Also clean the remote work directory. (only applies to workflows and CalcJobNodes)', | |
help='Also clean the remote work directories associated with the nodes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The point I wanted to make clear, is that doesn't apply if one pass a RemoteData node.
Just to respect traversal rule, and to make it easier, RemoteData directories can only be cleaned if the parent calcjob is passed to the function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The point I wanted to make clear, is that doesn't apply if one pass a RemoteData node.
I think it will also work if you pass a RemoteData
node, because the associated process node will be deleted thus the RemoteData
node itself will be cleaned.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you are right. I can improve the help message.
user = User.collection.get_default() | ||
counter = 0 | ||
for computer_uuid, paths in path_mapping.items(): | ||
computer = load_computer(uuid=computer_uuid) | ||
transport = AuthInfo.collection.get( | ||
dbcomputer_id=computer.pk, aiidauser_id=user.pk | ||
).get_transport() | ||
|
||
with transport: | ||
for remote_folder in paths: | ||
remote_folder._clean(transport=transport) | ||
counter += 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar code is used in calcjob_cleanworkdir
. Consider refactoring into a reusable function to avoid duplication.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I wanted modularize, but then I thought it's also used only in these two functions (here and calcjob_cleanworkdir
), Also it's specific codeme, I'm not sure if it worth to modularize it. 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's good to modularize as much as we can 😆 .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean it reduces the readability. If it's only for two use case.
But ok, I'll see what I can do. ;)
|
||
with transport: | ||
for remote_folder in paths: | ||
remote_folder._clean(transport=transport) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check if the remote folder is already cleaned or not, either here or inside the _clean
method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That already been done via flag only_not_cleaned
:
path_mapping = get_calcjob_remote_paths(calcjobs_pks, only_not_cleaned=True,)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good!
'Remote directories of nodes with the following pks would be cleaned: ' | ||
+ ' '.join(map(str, descendant_pks)) | ||
) | ||
click.confirm('Shall I continue?', abort=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The command asks for confirmation twice: 1) cleaning remote folders and 2) deleting nodes. I would prefer a single confirmation prompt by merging the messages into one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The main reason I did this, was to provide additional flexibility so to only clean Remote directories without actually deleting the nodes.
For instance in #4693 that might be useful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, it makes sense to me. 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my comment in the original OP, I think it should not add to verdi node
.
For the implementation, to avoid multi-layer of if..else, please consider using early return.
if not calcjobs_pks: | ||
echo.echo_report('--clean-workdir ignored. No CalcJobNode associated with the given node, found.') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can do early return here to avoid nested if..else.
if not path_mapping: | ||
echo.echo_report('--clean-workdir ignored. CalcJobNode work directories are already cleaned.') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Early return here as well?
else: | ||
descendant_pks = [remote_folder.pk for paths in path_mapping.values() for remote_folder in paths] | ||
|
||
if not force and not dry_run: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Early return?
) | ||
click.confirm('Shall I continue?', abort=True) | ||
|
||
if dry_run: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
early return as well?
@unkcpz Thanks for your suggestions,
Early return had to be avoided, because For more detailed behaviour, please also have a look at the tests. All scenarios and the expected behaviour are pictured, there.
The only fact it doesn't apply to add nodes, is not an issue itself, because
Anyways, I like your idea of having it as a subcommand of |
I believe you can ;) Just wrap the block inside
Nice.
You may misunderstood here for |
@@ -328,9 +328,14 @@ def extras(nodes, keys, fmt, identifier, raw): | |||
@click.argument('identifier', nargs=-1, metavar='NODES') | |||
@options.DRY_RUN() | |||
@options.FORCE() | |||
@click.option( | |||
'--clean-workdir', | |||
is_flag=True, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put default to True is backward incompatible and potentially danger.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, that's exactly what this command does :-)
It define it as a flag with is_flag=True
so the default value is False
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, right. Then could you write default=False
to be more explicit?
I don't get want you mean, sorry. Put the subcommand in |
I understand, but traversal rules affects only descendants of workchain and calcjob. As it has no effect or whatsoever on individual In the exact same way, '--clean-workdir' has no effect on |
True, but I feel like that's the expected behavior of While for |
I agree with @khsrali ,
|
@superstar54 applied your review. Now, it's more modular, and more readable. |
thanks for the work, LGTM! |
Implements #6732 also solves #4693.
Like the tiles says, now, with
verdi node delete --clean-workdir
one can also remove all remote directories of workflows and workchains.